define(["../common"], function() {
	
	var $form = $("#loginForm"),
	$msgWrap = $("#msgWrap"),
	loginDoPath = g_domain + "/member/loginDo/json";
	
	loadjs(["validator"],initValidator);

	$("[id^='submitBt_']").click(function() {
		$form.trigger('validate');
	});

	function initValidator() {
		
		$form.validator({
			messages: {required: '{0}不能为空'},
			fields: {
				name: {
					rule: "账户名:required",
					target: $msgWrap
				},
				password: {
					rule: "密码:required",
					target: $msgWrap
				}
			},
			valid: function(form){
				$msgWrap.tip("正在登录...", 'loading');
				var me = this;
				me.holdSubmit();
				$.post(loginDoPath, $form.serialize(), function(data){
						me.holdSubmit(false);
						if (data.status !== 0) {
							$msgWrap.tip("账户名或者密码错误", 'error', -1);
							return;
						} 
						$msgWrap.tip("登录成功!...", 'loading');
						if (data.result) {
							location.href = data.result;
						} else {
							location.href = g_domain;
						}
				});
			}
		});
	}
});
